<template>
	<view class="wm">
		<block v-if="news.length > 0">
			<news-item :news="news"></news-item>
		</block>
		<block v-else>
			<no-data></no-data>
		</block>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				queryObj:{
					pageNumber:1,
					length:10
				},
				news:[],
				isloading:false,
				total:1
			};
		},
		onLoad(){
			this.getAllNews();
		},
		methods:{
			/**
			 * 获取所有新闻列表
			 */
			async getAllNews(){
				//打开节流阀
				this.isloading = true;
				const {data:res} = await uni.$http.post("newss/getAllNews",this.queryObj);
				this.isloading = false;
				//请求失败
				if(res.meta.status !== 1) return uni.$showMsg();
				//请求成功
				this.news = [...this.news,...res.data];
				this.total = res.total;
			}
			
		},
		/**
		 * 新闻列表上拉加载更多
		 */
		onReachBottom(){
			//根据节流阀加载数据
			if(this.isloading) return;
			//让页码值自增+1
			this.queryObj.pageNumber++
			//如果当前pageNumber大于了最大页数则不加载
			if(this.queryObj.pageNumber <= this.total){
				this.getAllNews(); //请求数据
			}
		},
		
	}
</script>

<style lang="scss">


</style>
